﻿using Google.Protobuf;
using Server.Framework.Message;
using Server.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Message.Response
{
    /// <summary>
    /// Author: Leil
    /// Description: 角色列表回复消息
    /// CreateTime: 2020/5/13 12:31:32
    /// </summary>
    class PermissionListResp : ResponseBaseMessage
    {
        public List<PermissionDao> Permissions { get; } = new List<PermissionDao>();

        public int Count { get; set; }

        public PermissionListResp(int msgId):base(msgId)
        {

        }

        public override byte[] Serialize()
        {
            PermissionList msg = new PermissionList();
            Permissions.ForEach(permission =>
            {
                Permission p = new Permission
                {
                    Id = permission.ID,
                    PerCode = permission.PerCode ?? "",
                    Sort = permission.Sort,
                    Status = permission.Status,
                    Creator = permission.Creator ?? "",
                    CreateTime = permission.CreateTime ?? "",
                    Updator = permission.Updator ?? "",
                    UpdateTime = permission.UpdateTime ?? "",
                };
                msg.Permissions.Add(p);
            });
            msg.Count = Count;
            return msg.ToByteArray();
        }
    }
}
